<?php

require_once 'database.php';
require_once 'common.php';

$intTaskId = isset($_GET['taskUrl']) ?htmlspecialchars($_GET['taskUrl']) : 0;
$intStoryId = isset($_GET['id']) ?htmlspecialchars($_GET['id']) : 0;

$task = getTaskFromId($intTaskId, $intStoryId);

function getTaskFromId($intTaskIdParam, $intStoryIdParam){

	//Get the task from the database based on the ID
	$objTask = array();  //This will sit in memory waiting to be referenced by the HTML
	$objTask['task_id'] = $intTaskIdParam;
	$objTask['task_name'] = "New Task";
	$objTask['task_description'] = "";
	$objTask['estimated_hours'] = 0;
	$objTask['actual_hours'] = 0;
	$objTask['status'] = "Open";
	$objTask['story_id'] = 0;

	//If the value of the task id is 0, then we are creating a new project
	if($intTaskIdParam != 0){
		$dbResult = mysql_query("SELECT * FROM task WHERE task_id = $intTaskIdParam");
		$row = mysql_fetch_array($dbResult);

		$objTask['task_id'] = $row['task_id'];
		$objTask['task_name'] = $row['task_name'];
		$objTask['task_description'] = $row['task_description'];
		$objTask['estimated_hours'] = $row['estimated_hours'];
		$objTask['actual_hours'] = $row['actual_hours'];
		$objTask['status'] = $row['status'];
	}
	
	return $objTask;
}